window.__updateInterface = updateInterface;
window.__updatePreferences = updatePreferences;

window.updateInterface = function(serial, action, widget){
    __updateInterface(serial, action, widget);
    var serialString = '';

    if (serial)
    {
        for (var i = 0; i < serial.length; i++)
        {
            if (serial[i] != '')
                serialString += '&' + serial[i].hash;
        }
    }
    GroupEvent.fireEvent(action, jQuery.toJSON({
        "widget":widget,
        "serial":serialString
    }), "GUI");
}

window.updatePreferences = function(widgetId){
    var data = {
    };

    $('#editForm_'+widgetId + ' :input').each(function(){

        if (this.type == 'submit' || this.type == 'reset' || this.id == ('tagInput_' + widgetId))
            return;

        var pref = this.name.substr(10 + widgetId.length);

        data[pref] = this.value;
        widgetFactory.widgets[widgetId].manifest['preferences'][pref]['value'] = this.value;
    });
    GroupEvent.fireEvent(widgetId, jQuery.toJSON(data), "PREFERENCES");
    __updatePreferences(widgetId);
}
